package com.fantastic.service.zjs.impl;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.exception.sql.DeleteException;
import com.fantastic.common.exception.sql.InsertException;
import com.fantastic.common.exception.sql.SelectException;
import com.fantastic.common.utils.IsEmptyUtils;
import com.fantastic.mapper.zjs.VarietySpecTypeMapper;
import com.fantastic.model.pojo.zjs.VarietySpecType;
import com.fantastic.service.zjs.VarietySpecTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/5/30 18:37
 * @description: 菜品信息和菜品规格类型关联表service层接口实现类
 */
@Service
public class VarietySpecTypeServiceImpl implements VarietySpecTypeService {

    @Resource
    private VarietySpecTypeMapper varietySpecTypeMapper;

    /**
     * 查询
     *
     * @param varietySpecType
     * @return
     */
    @Override
    public List<VarietySpecType> listVarietySpecType(VarietySpecType varietySpecType) {
        List<VarietySpecType> varietySpecTypes = varietySpecTypeMapper.listVarietySpecType(varietySpecType);
        IsEmptyUtils.listIsEmpty(new SelectException(RespStatusInfo.SELECT_NULL), varietySpecTypes);
        return varietySpecTypes;
    }

    /**
     * 查询单个
     *
     * @param varietyId
     * @param specTypeId
     * @return
     */
    @Override
    public VarietySpecType getVarietySpecType(Integer varietyId, Integer specTypeId) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.DATA_ERROR), varietyId, specTypeId);
        return varietySpecTypeMapper.getVarietySpecType(varietyId, specTypeId);
    }

    /**
     * 添加
     *
     * @param varietySpecType
     * @return
     */
    @Override
    public Integer insertVarietySpecType(VarietySpecType varietySpecType) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.DATA_ERROR), varietySpecType.getVarietyId(), varietySpecType.getSpecTypeId());
        return varietySpecTypeMapper.insertVarietySpecType(varietySpecType);
    }

    /**
     * 批量添加
     *
     * @param varietySpecType
     * @return
     */
    @Transactional
    @Override
    public Integer insertVarietySpecTypes(ArrayList<VarietySpecType> varietySpecType) {
        try {
            return varietySpecTypeMapper.insertVarietySpecTypes(varietySpecType);
        } catch (Exception e) {
            throw new InsertException(RespStatusInfo.INSERT_ERROR);
        }

    }

    /**
     * 删除
     *
     * @param varietyId
     * @param specTypeId
     * @return
     */
    @Override
    public Integer deleteVarietySpecType(Integer varietyId, Integer specTypeId) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.DATA_ERROR), varietyId, specTypeId);
        return varietySpecTypeMapper.deleteVarietySpecType(varietyId, specTypeId);
    }

    /**
     * 批量删除
     *
     * @param varietyId
     * @param specTypeId
     */
    @Transactional
    @Override
    public Integer deleteVarietySpecTypes(Integer[] varietyId, Integer[] specTypeId) {
        try {
            return varietySpecTypeMapper.deleteVarietySpecTypes(varietyId, specTypeId);
        } catch (Exception e) {
            throw new DeleteException(RespStatusInfo.DELETE_ERROR);
        }
    }

}
